<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.eform.apptemplate.entity.tempName')">
              <a-input placeholder="" v-model="queryParam.tempName$lk"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.eform.apptemplate.entity.tempCode')">
              <a-input placeholder="" v-model="queryParam.tempCode$lk"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.eform.apptemplate.entity.tempType')">
                <a-select v-model="queryParam.tempType" placeholder="" :allowClear="true">
                  <a-select-option v-for="item in tempType" :key="item.value" :value="item.value">
                    {{item.text}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.eform.apptemplate.entity.tempStructure')">
                <a-select v-model="queryParam.tempStructure" placeholder="" :allowClear="true">
                  <a-select-option v-for="item in tempStructure" :key="item.value" :value="item.value">
                    {{item.text}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? this.$t('m.common.button.fold') : this.$t('m.common.button.expand') }}
                <ych-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
      <a-button @click="batchDel" type="default"  icon="delete">{{ $t('m.common.button.delete') }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{ $t('m.common.button.update') }}</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('m.common.button.more')}} <ych-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm :title="$t('m.common.tip.delete_confirm')" @confirm="() => handleDelete(record.id)">
                  <a>{{ $t('m.common.button.delete') }}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <actAppTemplate-modal ref="modalForm" @ok="modalFormOk"></actAppTemplate-modal>
  </a-card>
</template>

<script>

  import {YcListMixin} from '@/mixins/YcListMixin';
  import {filterMultiDictText} from '@/components/dict/YchDictSelectUtil';
  import ActAppTemplateModal from './modules/ActAppTemplateModal';
  import {EFormConstant} from "./EFormConstant";
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "ActAppTemplateList",
    mixins: [YcListMixin],
    components: {
      ActAppTemplateModal
    },
    data() {
      return {
        tempStructure: EFormConstant.objStructure,
        appType: EFormConstant.appType,
        tempType: EFormConstant.tempType,
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.eform.apptemplate.entity.tempName'),
            align: "center",
            dataIndex: 'tempName'
          },
          {
            title: this.$t('m.eform.apptemplate.entity.tempCode'),
            align: "center",
            dataIndex: 'tempCode'
          },
          {
            title: this.$t('m.eform.apptemplate.entity.tempType'),
            align: "center",
            dataIndex: 'tempType',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(EFormConstant.tempType, text + "")
              }
            }
          },
          {
            title: this.$t('m.eform.apptemplate.entity.tempStructure'),
            align: "center",
            dataIndex: 'tempStructure',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(EFormConstant.objStructure, text + "")
              }
            }
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'}
          }
        ],
        url: {
          list: YchConstant.PREFIX_EFORM + "/manage/actAppTemplate/list",
          delete: YchConstant.PREFIX_EFORM + "/manage/actAppTemplate/delete",
          deleteBatch: YchConstant.PREFIX_EFORM + "/manage/actAppTemplate/deleteBatch",
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
